package com.gdut.simple.view.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.gdut.simple.R;
import com.gdut.simple.data.entity.Post;
import com.gdut.simple.view.adapter.base.AbsRecyclerAdapter;
import com.gdut.simple.view.adapter.base.AbsViewHolder;

import java.util.List;

public class MyPostAdapter extends AbsRecyclerAdapter<Post> {


    public MyPostAdapter(Context context, List<Post> list) {
        super(context, list);
    }

    @Override
    protected AbsViewHolder createHolder(ViewGroup parent, int viewType) {
        return new ItemViewHolder(mInflater.inflate(R.layout.layout_my_post_item, parent, false));
    }

    @Override
    protected void showViewHolder(AbsViewHolder holder, int position) {
        final ItemViewHolder viewHolder = (ItemViewHolder) holder;
        if (mData.get(position).getContent() != null && !mData.get(position).getContent().isEmpty()) {
            viewHolder.content.setText(mData.get(position).getContent());
        } else {
            viewHolder.content.setVisibility(View.GONE);
        }
        viewHolder.time.setText(mData.get(position).getCreatedAt());
    }

    private static class ItemViewHolder extends AbsViewHolder {

        TextView content;
        TextView time;

        ItemViewHolder(View itemView) {
            super(itemView);
            content = (TextView) itemView.findViewById(R.id.id_post_content);
            time = (TextView) itemView.findViewById(R.id.id_post_time);
        }
    }
}
